﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using XKPlatform.Common.Extends;
using XKPlatform.DataModels;
using XKPlatform.Common;

namespace XKPlatform.Controllers
{
    public class SysUserRoleController : Controller
    {
        private readonly ISysUserRoleService _ISysUserRoleService;

        public SysUserRoleController(ISysUserRoleService ISysUserRoleService)
        {
            _ISysUserRoleService = ISysUserRoleService;
        }

        #region 新增
        [HttpPost]
        public JsonResult Save(SysUserRoleModel SysUserRoleModel, Guid? _formId)
        {
            if (!_formId.HasValue)
                return Json(new { code = 1, msg = "表单不存在！" });

            // 新增
            if (SysUserRoleModel.ID.IsNullOrEmpty())
            {
                int count = _ISysUserRoleService.Insert(SysUserRoleModel);

                return Json(new { code = count > 0 ? 0 : 1, updateData = SysUserRoleModel });
            }
            // 编辑 
            _ISysUserRoleService.Update(SysUserRoleModel, $" and Id='{SysUserRoleModel.ID}'");

            return Json(new { code = 0, updateData = SysUserRoleModel });

        }

        #endregion
    }
}